Skip to content

Clean up train rendering traits - #108

Merged
scaryrawr merged 2 commits into
mainfrom
scaryrawr/terminal-traits-cleanup
Jun 18, 2026
Merged

Clean up train rendering traits#108
scaryrawr merged 2 commits into
mainfrom
scaryrawr/terminal-traits-cleanup

Conversation

@scaryrawr

Copy link
Copy Markdown
Owner

The train renderer supported both real terminals and the web terminal through a combined display trait, but that made the boundary feel awkward: geometry, drawing, and failure handling were all tied together. This PR separates those concerns so the core renderer has a more natural API for both adapters.

Summary

  • Replaces the old Rust-facing Display/Options traits with explicit ScreenSize, TrainOptions, RenderTarget, and RenderError types.
  • Updates libsl rendering helpers and train entrypoints to pass dimensions separately and propagate render-target failures instead of requiring adapter-level unwraps.
  • Adapts the CLI and WASM wrappers to the new core API while preserving terminal behavior and the JS-facing WASM shape.
  • Adds focused libsl tests for clipping, offscreen completion, and target error propagation.

Validation

  • cargo fmt --all
  • cargo test --workspace
  • bun run test:websl
  • bun run build:websl
  • bun run typecheck:page
  • bun run test:page
  • cargo run -p sl -- --help

Split terminal dimensions from drawing in libsl, add a fallible render target API, and adapt the CLI and WASM wrappers to the cleaner Rust boundary while preserving behavior.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 18, 2026 15:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors libsl’s rendering interface to separate screen geometry, render options, and drawing/error handling so both the CLI terminal adapter and the WASM adapter can use a more natural core API.

Changes:

  • Replaces the old Display/Options traits with ScreenSize, TrainOptions, RenderTarget, and RenderError, and updates train entrypoints accordingly.
  • Updates core rendering helpers (mvaddstr, add_train, smoke/man helpers) to take explicit screen dimensions and propagate target draw failures.
  • Adapts the CLI and WASM bindings to the new API and adds focused libsl tests for clipping/offscreen/error propagation.
Show a summary per file
File Description
libraries/websl/src/lib.rs Updates WASM bindings to the new RenderTarget + ScreenSize/TrainOptions API and maps core errors into JS-visible outcomes.
libraries/libsl/src/mvaddstr.rs Refactors clipping/drawing helper to take ScreenSize + RenderTarget and return target errors; adds unit tests.
libraries/libsl/src/logo.rs Updates logo train entrypoint signature to the new rendering API types.
libraries/libsl/src/lib.rs Introduces ScreenSize, TrainOptions, RenderTarget, and RenderError as the new public core rendering surface.
libraries/libsl/src/d51.rs Updates D51 entrypoint to new API and adds an offscreen regression test.
libraries/libsl/src/c51.rs Updates C51 entrypoint to new API.
libraries/libsl/src/add_train.rs Refactors the main renderer loop to accept screen/options separately and propagate RenderTarget failures.
libraries/libsl/src/add_smoke.rs Updates smoke helper to use RenderTarget and return errors instead of swallowing failures.
libraries/libsl/src/add_man.rs Updates “man” helper to use RenderTarget and return errors instead of swallowing failures.
apps/sl/src/main.rs Adapts the CLI renderer to RenderTarget and properly distinguishes offscreen completion vs target I/O errors.

Copilot's findings

  • Files reviewed: 10/10 changed files
  • Comments generated: 3

Comment thread libraries/websl/src/lib.rs
Comment thread libraries/websl/src/lib.rs
Comment thread libraries/websl/src/lib.rs
Document that false means offscreen completion while render-target failures are thrown as JavaScript exceptions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@scaryrawr
scaryrawr merged commit 6beef42 into main Jun 18, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants